Option Explicit On Option Strict On Public Class Form1 Inherits System.Windows.Forms.Form Const min As Integer = 1 Const max As Integer = 100 Dim actual As Integer Friend WithEvents rtbGuesses As System.Windows.Forms.RichTextBox Friend WithEvents Label4 As System.Windows.Forms.Label Dim randGen As New Random #Region " Windows Form Designer generated code " ... deleted - code generated by IDE ... #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load LblQuery.Text = "I'm Thinking of a Number Between " & min & " and " & max actual = randGen.Next(1, max + 1) MsgBox("the actual is: " & actual) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim guess As Integer Dim guesses As Integer Dim isConverted As Boolean isConverted = Integer.TryParse(TxtNumber.Text, guesses) ' don't need to check # guesses because it is read only guesses = guesses + 1 ' ensure valid input isConverted = Integer.TryParse(TxtGuess.Text, guess) If isConverted Then TxtNumber.Text = guesses.ToString("n0") If guess = actual Then 'got it right rtbGuesses.AppendText(guess.ToString() & " Correct" & ControlChars.NewLine) LblFeedback.Text = "You're right!!!!" LblFeedback.ForeColor = Color.Red ElseIf guess > actual Then rtbGuesses.AppendText(guess.ToString() & " High" & ControlChars.NewLine) LblFeedback.Text = "Your guess is too high" Else rtbGuesses.AppendText(guess.ToString() & " Low" & ControlChars.NewLine) LblFeedback.Text = "Your guess is too low" End If TxtGuess.Clear() TxtGuess.Focus() Else MsgBox("Please enter a whole number") End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click actual = randGen.Next(1, max + 1) ' old way of random number generation!! ' actual = Convert.ToInt32((max - min + 1) * Rnd() + min) TxtNumber.Text = "0" TxtGuess.Text = "" LblFeedback.Text = "" LblFeedback.ForeColor = Color.Black rtbGuesses.Clear() End Sub End Class